﻿@model IList<string>

<input id="@Html.NameForModel()" name="@Html.NameForModel()" type="file" multiple="true">

<div id="FileList_@Html.NameForModel()"></div>


<div id="OldFileList_@Html.NameForModel()">
    @foreach (var item in Model)
    {
        <div>
            <a href="@item" target="_blank">@item</a>
            <input name="@Html.NameForModel()" type="hidden" value="@item" />
            &nbsp;
                <a href="javascript:;" onclick="$(this).parent().remove();">×</a>
        </div>
    }
</div>

<script type="text/javascript">
    $(function () {
        $("#@Html.NameForModel()").uploadify({
            'swf': '/scripts/uploadify/uploadify.swf', //IE9 不好用
            'buttonText': '选择文件',
            'uploader': '@Url.Action("add", "file", new { area = "" })',
            'onUploadSuccess': function (file, data, response) {
                $("<div><a href=\"" + data + "\" target=\"_blank\">" + data + "</a><input name=\"@Html.NameForModel()\" type=\"hidden\" value=\"" + data + "\" />&nbsp;<a href=\"javascript:;\" onclick=\"$(this).parent().remove();\">×</a></div>").appendTo('#FileList_@Html.NameForModel()');
            },
            'onUploadError': function (file, errorCode, errorMsg, errorString) {
                alert(file.name + '上传失败！');
            }
        });
    });
</script>
